#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

const int N = 1e5 + 10;
int a[N];

int main()
{
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	int k = n / 2 + 1;
	long long sum = 0;
	for (int i = 1; i <= n; i++)
	{
		sum += abs(a[k] - a[i]);
	}
	cout << sum;

	return 0;
}
